home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 November / PCWNOV07.iso / Software / Freeware / NSIS 2.29 / nsis-2.29-setup.exe / Include / Library.nsh < prev    next >
Encoding:
Text File  |  2007-04-27  |  19.9 KB  |  852 lines

  1. #
  2. # Library.nsh
  3. #
  4. # A system for the installation and uninstallation of dynamic
  5. # link libraries (DLL) and type libraries (TLB). Using this
  6. # system you can handle the complete setup with one single
  7. # line of code:
  8. #
  9. #  * File copying
  10. #  * File copying on reboot
  11. #  * Version checks
  12. #  * Registration and unregistration
  13. #  * Registration and unregistration on reboot
  14. #  * Shared DLL counting
  15. #  * Windows File Protection checks
  16. #
  17. # For more information, read appendix B in the documentation.
  18. #
  19.  
  20. !verbose push
  21. !verbose 3
  22.  
  23. !ifndef LIB_INCLUDED
  24.  
  25. !define LIB_INCLUDED
  26.  
  27. !ifndef SHCNE_ASSOCCHANGED
  28.   !define SHCNE_ASSOCCHANGED 0x08000000
  29. !endif
  30. !ifndef SHCNF_IDLIST
  31.   !define SHCNF_IDLIST 0x0000
  32. !endif
  33.  
  34. !include LogicLib.nsh
  35. !include x64.nsh
  36.  
  37. ### GetParent macro, don't pass $1 or $2 as INTPUT or OUTPUT
  38. !macro __InstallLib_Helper_GetParent INPUT OUTPUT
  39.  
  40.   # Copied from FileFunc.nsh
  41.  
  42.   StrCpy ${OUTPUT} ${INPUT}
  43.  
  44.   Push $1
  45.   Push $2
  46.  
  47.   StrCpy $2 ${OUTPUT} 1 -1
  48.   StrCmp $2 '\' 0 +3
  49.   StrCpy ${OUTPUT} ${OUTPUT} -1
  50.   goto -3
  51.  
  52.   StrCpy $1 0
  53.   IntOp $1 $1 - 1
  54.   StrCpy $2 ${OUTPUT} 1 $1
  55.   StrCmp $2 '\' +2
  56.   StrCmp $2 '' 0 -3
  57.   StrCpy ${OUTPUT} ${OUTPUT} $1
  58.  
  59.   Pop $2
  60.   Pop $1
  61.  
  62. !macroend
  63.  
  64. ### Initialize session id (GUID)
  65. !macro __InstallLib_Helper_InitSession
  66.  
  67.   !ifndef __InstallLib_SessionGUID_Defined
  68.  
  69.     !define __InstallLib_SessionGUID_Defined
  70.  
  71.     Var /GLOBAL __INSTALLLLIB_SESSIONGUID
  72.  
  73.   !endif
  74.  
  75.   !define __InstallLib_Helper_InitSession_Label "Library_${__FILE__}${__LINE__}"
  76.  
  77.   StrCmp $__INSTALLLLIB_SESSIONGUID '' 0 "${__InstallLib_Helper_InitSession_Label}"
  78.  
  79.     System::Call 'ole32::CoCreateGuid(g .s)'
  80.     Pop $__INSTALLLLIB_SESSIONGUID
  81.  
  82.   "${__InstallLib_Helper_InitSession_Label}:"
  83.  
  84.   !undef __InstallLib_Helper_InitSession_Label
  85.  
  86. !macroend
  87.  
  88. ### Add a RegTool entry to register after reboot
  89. !macro __InstallLib_Helper_AddRegToolEntry mode filename tempdir
  90.  
  91.   Push $R0
  92.   Push $R1
  93.   Push $R2
  94.   Push $R3
  95.  
  96.   ;------------------------
  97.   ;Copy the parameters
  98.  
  99.   Push "${filename}"
  100.   Push "${tempdir}"
  101.  
  102.   Pop $R2 ; temporary directory
  103.   Pop $R1 ; file name to register
  104.  
  105.   ;------------------------
  106.   ;Initialize session id
  107.  
  108.   !insertmacro __InstallLib_Helper_InitSession
  109.  
  110.   ;------------------------
  111.   ;Advance counter
  112.  
  113.   StrCpy $R0 0
  114.   ReadRegDWORD $R0 HKLM "Software\NSIS.Library.RegTool.v2\$__INSTALLLLIB_SESSIONGUID" "count"
  115.   IntOp $R0 $R0 + 1
  116.   WriteRegDWORD HKLM "Software\NSIS.Library.RegTool.v2\$__INSTALLLLIB_SESSIONGUID" "count" "$R0"
  117.  
  118.   ;------------------------
  119.   ;Setup RegTool
  120.  
  121.   ReadRegStr $R3 HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" "NSIS.Library.RegTool.v2"
  122.   StrCpy $R3 $R3 -4 1
  123.   IfFileExists $R3 +3
  124.  
  125.     File /oname=$R2\NSIS.Library.RegTool.v2.$__INSTALLLLIB_SESSIONGUID.exe "${NSISDIR}\Bin\RegTool.bin"
  126.     WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\RunOnce" \
  127.       "NSIS.Library.RegTool.v2" '"$R2\NSIS.Library.RegTool.v2.$__INSTALLLLIB_SESSIONGUID.exe" /S'
  128.  
  129.   ;------------------------
  130.   ;Add RegTool entry
  131.  
  132.   WriteRegStr HKLM "Software\NSIS.Library.RegTool.v2\$__INSTALLLLIB_SESSIONGUID" "$R0.file" "$R1"
  133.   WriteRegStr HKLM "Software\NSIS.Library.RegTool.v2\$__INSTALLLLIB_SESSIONGUID" "$R0.mode" "${mode}"
  134.  
  135.   Pop $R3
  136.   Pop $R2
  137.   Pop $R1
  138.   Pop $R0
  139.  
  140. !macroend
  141.  
  142. ### Get library version
  143. !macro __InstallLib_Helper_GetVersion TYPE FILE
  144.  
  145.   !tempfile LIBRARY_TEMP_NSH
  146.  
  147.   !ifdef NSIS_WIN32_MAKENSIS
  148.  
  149.     !execute '"${NSISDIR}\Bin\LibraryLocal.exe" "${TYPE}" "${FILE}" "${LIBRARY_TEMP_NSH}"'
  150.  
  151.   !else
  152.  
  153.     !execute 'LibraryLocal "${TYPE}" "${FILE}" "${LIBRARY_TEMP_NSH}"'
  154.  
  155.     !if ${TYPE} == 'T'
  156.  
  157.       !warning "LibraryLocal currently supports TypeLibs version detection on Windows only"
  158.  
  159.     !endif
  160.  
  161.   !endif
  162.  
  163.   !include "${LIBRARY_TEMP_NSH}"
  164.   !delfile "${LIBRARY_TEMP_NSH}"
  165.   !undef LIBRARY_TEMP_NSH
  166.  
  167. !macroend
  168.  
  169. ### Install library
  170. !macro InstallLib libtype shared install localfile destfile tempbasedir
  171.  
  172.   !verbose push
  173.   !verbose 3
  174.  
  175.   Push $R0
  176.   Push $R1
  177.   Push $R2
  178.   Push $R3
  179.   Push $R4
  180.   Push $R5
  181.  
  182.   ;------------------------
  183.   ;Define
  184.  
  185.   !define INSTALLLIB_UNIQUE "${__FILE__}${__LINE__}"
  186.  
  187.   !define INSTALLLIB_LIBTYPE_${libtype}
  188.   !define INSTALLLIB_LIBTYPE_SET INSTALLLIB_LIBTYPE_${libtype}
  189.   !define INSTALLLIB_SHARED_${shared}
  190.   !define INSTALLLIB_SHARED_SET INSTALLLIB_SHARED_${shared}
  191.   !define INSTALLLIB_INSTALL_${install}
  192.   !define INSTALLLIB_INSTALL_SET INSTALLLIB_INSTALL_${install}
  193.  
  194.   ;------------------------
  195.   ;Validate
  196.  
  197.   !ifndef INSTALLLIB_LIBTYPE_DLL & INSTALLLIB_LIBTYPE_REGDLL & INSTALLLIB_LIBTYPE_TLB & \
  198.     INSTALLLIB_LIBTYPE_REGDLLTLB
  199.     !error "InstallLib: Incorrect setting for parameter: libtype"
  200.   !endif
  201.  
  202.   !ifndef INSTALLLIB_INSTALL_REBOOT_PROTECTED & INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED & \
  203.     INSTALLLIB_INSTALL_NOREBOOT_PROTECTED & INSTALLLIB_INSTALL_NOREBOOT_NOTPROTECTED
  204.     !error "InstallLib: Incorrect setting for parameter: install"
  205.   !endif
  206.  
  207.   ;------------------------
  208.   ;x64 settings
  209.  
  210.   !ifdef LIBRARY_X64
  211.  
  212.     ${DisableX64FSRedirection}
  213.  
  214.   !endif
  215.  
  216.   ;------------------------
  217.   ;Copy the parameters used on run-time to a variable
  218.   ;This allows the usage of variables as parameter
  219.  
  220.   StrCpy $R4 "${destfile}"
  221.   StrCpy $R5 "${tempbasedir}"
  222.  
  223.   ;------------------------
  224.   ;Shared library count
  225.  
  226.   !ifndef INSTALLLIB_SHARED_NOTSHARED
  227.  
  228.     StrCmp ${shared} "" 0 "installlib.noshareddllincrease_${INSTALLLIB_UNIQUE}"
  229.  
  230.       !ifdef LIBRARY_X64
  231.  
  232.         SetRegView 64
  233.  
  234.       !endif
  235.  
  236.       ReadRegDword $R0 HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R4
  237.       ClearErrors
  238.       IntOp $R0 $R0 + 1
  239.       WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R4 $R0
  240.  
  241.       !ifdef LIBRARY_X64
  242.  
  243.         SetRegView 32
  244.  
  245.       !endif
  246.  
  247.     "installlib.noshareddllincrease_${INSTALLLIB_UNIQUE}:"
  248.  
  249.   !endif
  250.  
  251.   ;------------------------
  252.   ;Check Windows File Protection
  253.  
  254.   !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_NOREBOOT_PROTECTED
  255.  
  256.     !define LIBRARY_DEFINE_DONE_LABEL
  257.  
  258.     System::Call "sfc::SfcIsFileProtected(i 0, w R4) i.R0"
  259.  
  260.       StrCmp $R0 "error" "installlib.notprotected_${INSTALLLIB_UNIQUE}"
  261.       StrCmp $R0 "0" "installlib.notprotected_${INSTALLLIB_UNIQUE}"
  262.  
  263.     Goto "installlib.done_${INSTALLLIB_UNIQUE}"
  264.  
  265.     "installlib.notprotected_${INSTALLLIB_UNIQUE}:"
  266.  
  267.   !endif
  268.  
  269.   ;------------------------
  270.   ;Check file
  271.  
  272.   IfFileExists $R4 0 "installlib.copy_${INSTALLLIB_UNIQUE}"
  273.  
  274.   ;------------------------
  275.   ;Get version information
  276.  
  277.   !ifndef LIBRARY_IGNORE_VERSION
  278.  
  279.     !insertmacro __InstallLib_Helper_GetVersion D "${LOCALFILE}"
  280.  
  281.     !ifdef LIBRARY_VERSION_FILENOTFOUND
  282.       !error "InstallLib: The library ${LOCALFILE} could not be found."
  283.     !endif
  284.  
  285.     !ifndef LIBRARY_VERSION_NONE
  286.  
  287.       !define LIBRARY_DEFINE_UPGRADE_LABEL
  288.       !define LIBRARY_DEFINE_REGISTER_LABEL
  289.  
  290.       StrCpy $R0 ${LIBRARY_VERSION_HIGH}
  291.       StrCpy $R1 ${LIBRARY_VERSION_LOW}
  292.  
  293.       GetDLLVersion $R4 $R2 $R3
  294.  
  295.       !undef LIBRARY_VERSION_HIGH
  296.       !undef LIBRARY_VERSION_LOW
  297.  
  298.       !ifndef INSTALLLIB_LIBTYPE_TLB & INSTALLLIB_LIBTYPE_REGDLLTLB
  299.  
  300.         IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  301.         IntCmpU $R1 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.register_${INSTALLLIB_UNIQUE}" \
  302.           "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  303.  
  304.       !else
  305.  
  306.         !insertmacro __InstallLib_Helper_GetVersion T "${LOCALFILE}"
  307.  
  308.         !ifdef LIBRARY_VERSION_FILENOTFOUND
  309.           !error "InstallLib: The library ${LOCALFILE} could not be found."
  310.         !endif
  311.  
  312.         !ifndef LIBRARY_VERSION_NONE
  313.  
  314.           IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  315.           IntCmpU $R1 $R3 0 "installlib.register_${INSTALLLIB_UNIQUE}" \
  316.             "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  317.  
  318.         !else
  319.  
  320.           IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  321.           IntCmpU $R1 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.register_${INSTALLLIB_UNIQUE}" \
  322.             "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  323.  
  324.         !endif
  325.  
  326.       !endif
  327.  
  328.     !else
  329.  
  330.       !undef LIBRARY_VERSION_NONE
  331.  
  332.       !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  333.  
  334.         !insertmacro __InstallLib_Helper_GetVersion T "${LOCALFILE}"
  335.  
  336.       !endif
  337.  
  338.     !endif
  339.  
  340.     !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  341.  
  342.       !ifndef LIBRARY_VERSION_NONE
  343.  
  344.         !ifndef LIBRARY_DEFINE_UPGRADE_LABEL
  345.  
  346.           !define LIBRARY_DEFINE_UPGRADE_LABEL
  347.  
  348.         !endif
  349.  
  350.         !ifndef LIBRARY_DEFINE_REGISTER_LABEL
  351.  
  352.           !define LIBRARY_DEFINE_REGISTER_LABEL
  353.  
  354.         !endif
  355.  
  356.         StrCpy $R0 ${LIBRARY_VERSION_HIGH}
  357.         StrCpy $R1 ${LIBRARY_VERSION_LOW}
  358.  
  359.         TypeLib::GetLibVersion $R4
  360.         Pop $R3
  361.         Pop $R2
  362.  
  363.         IntCmpU $R0 $R2 0 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  364.         IntCmpU $R1 $R3 "installlib.register_${INSTALLLIB_UNIQUE}" "installlib.register_${INSTALLLIB_UNIQUE}" \
  365.           "installlib.upgrade_${INSTALLLIB_UNIQUE}"
  366.  
  367.         !undef LIBRARY_VERSION_HIGH
  368.         !undef LIBRARY_VERSION_LOW
  369.  
  370.       !else
  371.  
  372.         !undef LIBRARY_VERSION_NONE
  373.  
  374.       !endif
  375.  
  376.     !endif
  377.  
  378.   !endif
  379.  
  380.   ;------------------------
  381.   ;Upgrade
  382.  
  383.   !ifdef LIBRARY_DEFINE_UPGRADE_LABEL
  384.  
  385.     !undef LIBRARY_DEFINE_UPGRADE_LABEL
  386.  
  387.     "installlib.upgrade_${INSTALLLIB_UNIQUE}:"
  388.  
  389.   !endif
  390.  
  391.   ;------------------------
  392.   ;Copy
  393.  
  394.   !ifdef INSTALLLIB_INSTALL_NOREBOOT_PROTECTED | INSTALLLIB_INSTALL_NOREBOOT_NOTPROTECTED
  395.  
  396.     "installlib.copy_${INSTALLLIB_UNIQUE}:"
  397.  
  398.     StrCpy $R0 $R4
  399.     Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  400.  
  401.   !else
  402.  
  403.     !ifndef LIBRARY_DEFINE_REGISTER_LABEL
  404.  
  405.       !define LIBRARY_DEFINE_REGISTER_LABEL
  406.  
  407.     !endif
  408.  
  409.     !ifndef LIBRARY_DEFINE_DONE_LABEL
  410.  
  411.       !define LIBRARY_DEFINE_DONE_LABEL
  412.  
  413.     !endif
  414.  
  415.     ClearErrors
  416.  
  417.     StrCpy $R0 $R4
  418.     Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  419.  
  420.     IfErrors 0 "installlib.register_${INSTALLLIB_UNIQUE}"
  421.  
  422.     SetOverwrite lastused
  423.  
  424.     ;------------------------
  425.     ;Copy on reboot
  426.  
  427.     GetTempFileName $R0 $R5
  428.     Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  429.     Rename /REBOOTOK $R0 $R4
  430.  
  431.     ;------------------------
  432.     ;Register on reboot
  433.  
  434.     Call ":installlib.regonreboot_${INSTALLLIB_UNIQUE}"
  435.  
  436.     Goto "installlib.done_${INSTALLLIB_UNIQUE}"
  437.  
  438.     "installlib.copy_${INSTALLLIB_UNIQUE}:"
  439.       StrCpy $R0 $R4
  440.       Call ":installlib.file_${INSTALLLIB_UNIQUE}"
  441.  
  442.   !endif
  443.  
  444.   ;------------------------
  445.   ;Register
  446.  
  447.   !ifdef LIBRARY_DEFINE_REGISTER_LABEL
  448.  
  449.     !undef LIBRARY_DEFINE_REGISTER_LABEL
  450.  
  451.     "installlib.register_${INSTALLLIB_UNIQUE}:"
  452.  
  453.   !endif
  454.  
  455.   !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  456.  
  457.     !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  458.  
  459.       IfRebootFlag 0 "installlib.regnoreboot_${INSTALLLIB_UNIQUE}"
  460.  
  461.         Call ":installlib.regonreboot_${INSTALLLIB_UNIQUE}"
  462.  
  463.         Goto "installlib.registerfinish_${INSTALLLIB_UNIQUE}"
  464.  
  465.       "installlib.regnoreboot_${INSTALLLIB_UNIQUE}:"
  466.  
  467.     !endif
  468.  
  469.     !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  470.  
  471.       TypeLib::Register $R4
  472.  
  473.     !endif
  474.  
  475.     !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_REGDLLTLB
  476.  
  477.       !ifndef LIBRARY_X64
  478.  
  479.         RegDll $R4
  480.  
  481.       !else
  482.  
  483.         ExecWait '"$SYSDIR\regsvr32.exe" /s "$R4"'
  484.  
  485.       !endif
  486.  
  487.     !endif
  488.  
  489.     !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  490.  
  491.       "installlib.registerfinish_${INSTALLLIB_UNIQUE}:"
  492.  
  493.     !endif
  494.  
  495.   !endif
  496.  
  497.   !ifdef LIBRARY_SHELL_EXTENSION
  498.  
  499.     System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
  500.  
  501.   !endif
  502.  
  503.   !ifdef LIBRARY_COM
  504.  
  505.     System::Call 'Ole32::CoFreeUnusedLibraries()'
  506.  
  507.   !endif
  508.  
  509.   ;------------------------
  510.   ;Done
  511.  
  512.   !ifdef LIBRARY_DEFINE_DONE_LABEL
  513.  
  514.     !undef LIBRARY_DEFINE_DONE_LABEL
  515.  
  516.   "installlib.done_${INSTALLLIB_UNIQUE}:"
  517.  
  518.   !endif
  519.  
  520.   Pop $R5
  521.   Pop $R4
  522.   Pop $R3
  523.   Pop $R2
  524.   Pop $R1
  525.   Pop $R0
  526.  
  527.   ;------------------------
  528.   ;End
  529.  
  530.   Goto "installlib.end_${INSTALLLIB_UNIQUE}"
  531.  
  532.   ;------------------------
  533.   ;Extract
  534.  
  535.   !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  536.  
  537.     SetOverwrite try
  538.  
  539.   !else
  540.  
  541.     SetOverwrite on
  542.  
  543.   !endif
  544.  
  545.   "installlib.file_${INSTALLLIB_UNIQUE}:"
  546.     SetFileAttributes $R0 FILE_ATTRIBUTE_NORMAL
  547.     ClearErrors
  548.     File /oname=$R0 "${LOCALFILE}"
  549.     Return
  550.  
  551.   SetOverwrite lastused
  552.  
  553.   ;------------------------
  554.   ;Register on reboot
  555.  
  556.   !ifdef INSTALLLIB_INSTALL_REBOOT_PROTECTED | INSTALLLIB_INSTALL_REBOOT_NOTPROTECTED
  557.  
  558.     "installlib.regonreboot_${INSTALLLIB_UNIQUE}:"
  559.  
  560.       !ifdef INSTALLLIB_LIBTYPE_REGDLL | INSTALLLIB_LIBTYPE_REGDLLTLB
  561.         !ifndef LIBRARY_X64
  562.           !insertmacro __InstallLib_Helper_AddRegToolEntry 'D' "$R4" "$R5"
  563.         !else
  564.           !insertmacro __InstallLib_Helper_AddRegToolEntry 'DX' "$R4" "$R5"
  565.         !endif
  566.       !endif
  567.  
  568.       !ifdef INSTALLLIB_LIBTYPE_TLB | INSTALLLIB_LIBTYPE_REGDLLTLB
  569.         !insertmacro __InstallLib_Helper_AddRegToolEntry 'T' "$R4" "$R5"
  570.       !endif
  571.  
  572.       Return
  573.  
  574.   !endif
  575.  
  576.   ;------------------------
  577.   ;End label
  578.  
  579.   "installlib.end_${INSTALLLIB_UNIQUE}:"
  580.  
  581.   !ifdef LIBRARY_X64
  582.  
  583.     ${EnableX64FSRedirection}
  584.  
  585.   !endif
  586.  
  587.   ;------------------------
  588.   ;Undefine
  589.  
  590.   !undef INSTALLLIB_UNIQUE
  591.  
  592.   !undef ${INSTALLLIB_LIBTYPE_SET}
  593.   !undef INSTALLLIB_LIBTYPE_SET
  594.   !undef ${INSTALLLIB_SHARED_SET}
  595.   !undef INSTALLLIB_SHARED_SET
  596.   !undef ${INSTALLLIB_INSTALL_SET}
  597.   !undef INSTALLLIB_INSTALL_SET
  598.  
  599.   !verbose pop
  600.  
  601. !macroend
  602.  
  603. ### Uninstall library
  604. !macro UnInstallLib libtype shared uninstall file
  605.  
  606.   !verbose push
  607.   !verbose 3
  608.  
  609.   Push $R0
  610.   Push $R1
  611.  
  612.   ;------------------------
  613.   ;Define
  614.  
  615.   !define UNINSTALLLIB_UNIQUE "${__FILE__}${__LINE__}"
  616.  
  617.   !define UNINSTALLLIB_LIBTYPE_${libtype}
  618.   !define UNINSTALLLIB_LIBTYPE_SET UNINSTALLLIB_LIBTYPE_${libtype}
  619.   !define UNINSTALLLIB_SHARED_${shared}
  620.   !define UNINSTALLLIB_SHARED_SET UNINSTALLLIB_SHARED_${shared}
  621.   !define UNINSTALLLIB_UNINSTALL_${uninstall}
  622.   !define UNINSTALLLIB_UNINSTALL_SET UNINSTALLLIB_UNINSTALL_${uninstall}
  623.  
  624.   ;------------------------
  625.   ;Validate
  626.  
  627.   !ifndef UNINSTALLLIB_LIBTYPE_DLL & UNINSTALLLIB_LIBTYPE_REGDLL & UNINSTALLLIB_LIBTYPE_TLB & \
  628.     UNINSTALLLIB_LIBTYPE_REGDLLTLB
  629.     !error "UnInstallLib: Incorrect setting for parameter: libtype"
  630.   !endif
  631.  
  632.   !ifndef UNINSTALLLIB_SHARED_NOTSHARED & UNINSTALLLIB_SHARED_SHARED
  633.     !error "UnInstallLib: Incorrect setting for parameter: shared"
  634.   !endif
  635.  
  636.   !ifndef UNINSTALLLIB_UNINSTALL_NOREMOVE & UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED & \
  637.     UNINSTALLLIB_UNINSTALL_REBOOT_NOTPROTECTED & UNINSTALLLIB_UNINSTALL_NOREBOOT_PROTECTED & \
  638.     UNINSTALLLIB_UNINSTALL_NOREBOOT_NOTPROTECTED
  639.     !error "UnInstallLib: Incorrect setting for parameter: uninstall"
  640.   !endif
  641.  
  642.   ;------------------------
  643.   ;x64 settings
  644.  
  645.   !ifdef LIBRARY_X64
  646.  
  647.     ${DisableX64FSRedirection}
  648.  
  649.   !endif
  650.  
  651.   ;------------------------
  652.   ;Copy the parameters used on run-time to a variable
  653.   ;This allows the usage of variables as parameter
  654.  
  655.   StrCpy $R1 "${file}"
  656.  
  657.   ;------------------------
  658.   ;Shared library count
  659.  
  660.   !ifdef UNINSTALLLIB_SHARED_SHARED
  661.  
  662.     !define UNINSTALLLIB_DONE_LABEL
  663.  
  664.     !ifdef LIBRARY_X64
  665.  
  666.       SetRegView 64
  667.  
  668.     !endif
  669.  
  670.     ReadRegDword $R0 HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1
  671.     StrCmp $R0 "" "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}"
  672.  
  673.     IntOp $R0 $R0 - 1
  674.     IntCmp $R0 0 "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}" \
  675.       "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}" "uninstalllib.shareddllinuse_${UNINSTALLLIB_UNIQUE}"
  676.  
  677.     "uninstalllib.shareddllremove_${UNINSTALLLIB_UNIQUE}:"
  678.       DeleteRegValue HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1
  679.       !ifndef UNINSTALLLIB_SHARED_SHAREDNOREMOVE
  680.         Goto "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}"
  681.       !endif
  682.  
  683.     "uninstalllib.shareddllinuse_${UNINSTALLLIB_UNIQUE}:"
  684.       WriteRegDWORD HKLM Software\Microsoft\Windows\CurrentVersion\SharedDLLs $R1 $R0
  685.  
  686.         !ifdef LIBRARY_X64
  687.  
  688.           SetRegView 32
  689.  
  690.         !endif
  691.  
  692.       Goto "uninstalllib.done_${UNINSTALLLIB_UNIQUE}"
  693.  
  694.     "uninstalllib.shareddlldone_${UNINSTALLLIB_UNIQUE}:"
  695.  
  696.     !ifdef LIBRARY_X64
  697.  
  698.       SetRegView 32
  699.  
  700.     !endif
  701.  
  702.   !endif
  703.  
  704.   ;------------------------
  705.   ;Remove
  706.  
  707.   !ifndef UNINSTALLLIB_UNINSTALL_NOREMOVE
  708.  
  709.     ;------------------------
  710.     ;Check Windows File Protection
  711.  
  712.     !ifdef UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED | UNINSTALLLIB_UNINSTALL_NOREBOOT_PROTECTED
  713.  
  714.       !ifndef UNINSTALLLIB_DONE_LABEL
  715.  
  716.         !define UNINSTALLLIB_DONE_LABEL
  717.  
  718.       !endif
  719.  
  720.       System::Call "sfc::SfcIsFileProtected(i 0, w $R1) i.R0"
  721.  
  722.         StrCmp $R0 "error" "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}"
  723.         StrCmp $R0 "0" "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}"
  724.  
  725.       Goto "uninstalllib.done_${UNINSTALLLIB_UNIQUE}"
  726.  
  727.       "uninstalllib.notprotected_${UNINSTALLLIB_UNIQUE}:"
  728.  
  729.     !endif
  730.  
  731.     ;------------------------
  732.     ;Unregister
  733.  
  734.     !ifdef UNINSTALLLIB_LIBTYPE_REGDLL | UNINSTALLLIB_LIBTYPE_REGDLLTLB
  735.  
  736.       !ifndef LIBRARY_X64
  737.  
  738.         UnRegDLL $R1
  739.  
  740.       !else
  741.  
  742.         ExecWait '"$SYSDIR\regsvr32.exe" /s /u "$R1"'
  743.  
  744.       !endif
  745.  
  746.     !endif
  747.  
  748.     !ifdef UNINSTALLLIB_LIBTYPE_TLB | UNINSTALLLIB_LIBTYPE_REGDLLTLB
  749.  
  750.       TypeLib::UnRegister $R1
  751.  
  752.     !endif
  753.  
  754.     !ifdef LIBRARY_SHELL_EXTENSION
  755.  
  756.       System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
  757.  
  758.     !endif
  759.  
  760.     !ifdef LIBRARY_COM
  761.  
  762.       System::Call 'Ole32::CoFreeUnusedLibraries()'
  763.  
  764.     !endif
  765.  
  766.     ;------------------------
  767.     ;Delete
  768.  
  769.     Delete $R1
  770.  
  771.     !ifdef UNINSTALLLIB_UNINSTALL_REBOOT_PROTECTED | UNINSTALLLIB_UNINSTALL_REBOOT_NOTPROTECTED
  772.  
  773.       ${If} ${FileExists} $R1
  774.         # File is in use, can't just delete.
  775.         # Move file to another location before using Delete /REBOOTOK. This way, if
  776.         #  the user installs a new version of the DLL, it won't be deleted after
  777.         #  reboot. See bug #1097642 for more information on this.
  778.  
  779.         # Try moving to $TEMP.
  780.         GetTempFileName $R0
  781.         Delete $R0
  782.         Rename $R1 $R0
  783.  
  784.         ${If} ${FileExists} $R1
  785.           # Still here, delete temporary file, in case the file was copied
  786.           #  and not deleted. This happens when moving from network drives,
  787.           #  for example.
  788.           Delete $R0
  789.  
  790.           # Try moving to directory containing the file.
  791.           !insertmacro __InstallLib_Helper_GetParent $R1 $R0
  792.           GetTempFileName $R0 $R0
  793.           Delete $R0
  794.           Rename $R1 $R0
  795.  
  796.           ${If} ${FileExists} $R1
  797.             # Still here, delete temporary file.
  798.             Delete $R0
  799.  
  800.             # Give up moving, simply Delete /REBOOTOK the file.
  801.             StrCpy $R0 $R1
  802.           ${EndIf}
  803.         ${EndIf}
  804.  
  805.         # Delete the moved file.
  806.         Delete /REBOOTOK $R0
  807.       ${EndIf}
  808.  
  809.     !endif
  810.  
  811.   !endif
  812.  
  813.   ;------------------------
  814.   ;Done
  815.  
  816.   !ifdef UNINSTALLLIB_DONE_LABEL
  817.  
  818.     !undef UNINSTALLLIB_DONE_LABEL
  819.  
  820.     "uninstalllib.done_${UNINSTALLLIB_UNIQUE}:"
  821.  
  822.   !endif
  823.  
  824.   !ifdef LIBRARY_X64
  825.  
  826.     ${EnableX64FSRedirection}
  827.  
  828.   !endif
  829.  
  830.   Pop $R1
  831.   Pop $R0
  832.  
  833.   ;------------------------
  834.   ;Undefine
  835.  
  836.   !undef UNINSTALLLIB_UNIQUE
  837.  
  838.   !undef ${UNINSTALLLIB_LIBTYPE_SET}
  839.   !undef UNINSTALLLIB_LIBTYPE_SET
  840.   !undef ${UNINSTALLLIB_SHARED_SET}
  841.   !undef UNINSTALLLIB_SHARED_SET
  842.   !undef ${UNINSTALLLIB_UNINSTALL_SET}
  843.   !undef UNINSTALLLIB_UNINSTALL_SET
  844.  
  845.   !verbose pop
  846.  
  847. !macroend
  848.  
  849. !endif
  850.  
  851. !verbose pop
  852.